<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <%@include file="/res/include/base-head.jsp"%>
	<%@include file="/res/include/jquery-easyui.jsp"%>
	<script type="text/javascript" src="${pageContext.request.contextPath}/res/js/draw/drawItem.js"></script>
  </head>
  <body>
<form id="data-form">
	<div class="form_item">
	<input  type="hidden" name="id" value="${drawItemVo.id}"/>
	<dl>
        <dt>名称：</dt>
        <dd><input type="text" name="name" value="${drawItemVo.name }" class="txt grid-25" maxlength="32"/></dd>
    </dl>
   <dl>
    	<dt>图片：</dt>
        <dd>
        	<ul class="product_imglist img_imglist">
	        	<c:choose>
	        	<c:when test="${!empty drawItemVo && !empty drawItemVo.img}">
		        	<li>
		     			<a href="javascript:;" class="item" id="img" onclick="admin.drawItem.addImg('img')"><p class="img"><img src="http://file.xfquanquan.com${drawItemVo.img }" alt="" /></p></a>
		     			<em onclick="delLogoImg(this)"></em>
		     		</li>
	        	</c:when>
	        	<c:otherwise>
	        		<li><a href="javascript:;" class="item" id="img" onclick="admin.drawItem.addImg('img')">添加图片</a></li>
	        	</c:otherwise>
	        	</c:choose>	
         	</ul>
        </dd>
    </dl>
    <dl>
			<dt>优惠券：</dt>
			<dd>
				<select name="couponId" id="couponId">
					<option value="">请选择</option>
					<c:forEach var="item" items="${couponList}">
						<option  <c:if test="${item.id == drawItemVo.couponId}">selected="selected"</c:if> value="${item.id}">${item.name}</option>
					</c:forEach>
				</select>
			</dd>
	</dl>
		<p class="page_btn"><input type="button" id="saveBtn" value="保存" class="btn_blue" onclick="edit();"/></p>
	</div>
</form>
<script type="text/javascript">

function delLogoImg(obj,index){
	$(obj).closest('li').html('<a href="javascript:;" class="item" id="img" onclick="admin.drawItem.addImg(\'img\')">添加图片</a>');
}
function edit() {
	if(!$('#data-form').form('validate')) return;
	var data=$('#data-form').form('jsonObject');
	var img = "";
	var imglist = $(".img_imglist img");
	if (imglist && imglist.length > 0) {
		imglist.each(function(){
		    if (img == "") {
		    	img += $(this).attr("src").replace(imgFilePath,"");
		    } else {
		    	img += ";" + $(this).attr("src").replace(imgFilePath,"");
		    }
		});
	}
	data.img = img;
	$.post(contextPath+'/draw/item/update',data,function(result) {
		if(result.code==1) {
			top.showInfo('修改成功!');
			var url=contextPath+'/draw/item/detail?id='+data.id;
			top.addTab(data.id,data.name, url);
		} else {
			if (result.msg) {
				top.showInfo(result.msg);
			} else {
				top.showInfo('修改失败!');
			}
		}
	});
}

</script>
</body>
</html>
